package com.suapi.project.service.innerImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suapi.project.common.ErrorCode;
import com.suapi.project.exception.BusinessException;
import com.suapi.project.mapper.UserMapper;
import com.suapi.suapicommon.model.entity.User;
import com.suapi.suapicommon.service.InnerUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class InnerUserServiceImpl implements InnerUserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据 ak 查询
     * @param accessKey
     * @return
     */
    @Override
    public User getInvokerUser(String accessKey) {
        if (StringUtils.isAnyBlank(accessKey)){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("accessKey",accessKey);
        User user = userMapper.selectOne(userQueryWrapper);
        System.out.println(user);
        return user;
    }

}
